package Test;

import java.lang.reflect.Field;

public class TestInteger {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Integer a = 10002;
        Integer b = 20001;
        System.out.println(a+" "+b);
        swag(a,b);
        System.out.println(a+" "+b);
        swag2(a,b);
        System.out.println(a+" "+b);


    }
    // 还是值传递
    public static void swag(Integer a, Integer b){
        Integer temp =a.intValue();
        a = new Integer(b.intValue());
        b = new Integer(temp);
    }
    // 引用传递,需要反射来实现
    public static void swag2(Integer a,Integer b) throws IllegalAccessException, NoSuchFieldException {
        Field field = Integer.class.getDeclaredField("value");
        field.setAccessible(true);
        Integer tmp =  new Integer(a.intValue());
        field.set(a,b);
        field.set(b,tmp);
    }
}
